class Solution3 {
    //统一比较
    public static String longestCommonPrefix(String[] strs) {
        //边界条件
        if (strs.length == 1) {
            return strs[0];
        }
        //纵向扫描
        //"flower"
        //"flow"
        //"flight"
        //里面有几个字符串
        int count = strs.length;
        //以第一个字符串为基准
        int length = strs[0].length();
        for (int i = 0; i < length; i++) {
            char ch = strs[0].charAt(i);
            for (int j = 1; j < count; j++) {
                if (strs[j].length() <= i || strs[j].charAt(i) != ch) {
                    return strs[0].substring(0,i);
                }
            }
        }
        return strs[0];
    }

    public static void main(String[] args) {
        String[] strs = new String[]{"cir", "car"};
        String s = Solution3.longestCommonPrefix(strs);
        System.out.println(s);
    }
}